package wanxiang

import (
	"fmt"
	"gitee.com/gam6it/SecToolkit/utils/http2"
)

const (
	JobStatusRunning = "Running"
	JobStatusSuccess = "Success"
	JobStatusFailed  = "Failed"
)

// GetAssetFreshStatus 获取资产信息扫描状态，输入任务Id，返回状态值
func (c *Client) GetAssetFreshStatus(jobId string) (string, error) {
	type resp struct {
		ID           string `json:"id,omitempty"`
		Status       string `json:"status,omitempty"`
		Success      bool   `json:"success,omitempty"`
		ErrorCode    string `json:"errorCode,omitempty"`
		ErrorMessage string `json:"errorMessage,omitempty"`
	}
	var req = map[string]string{
		"id": jobId,
	}
	var result resp
	api := fmt.Sprintf("/external/api/assets/refreshjob/%s", jobId)
	err := c.Request(http2.MethodGet, api, &result, req)
	if err != nil || result.ErrorCode != "" {
		return "", fmt.Errorf("获取资产任务状态，错误码：%s，错误信息：%s，错误内容：%v", result.ErrorCode, result.ErrorMessage, err)
	}
	return result.Status, nil
}
